package com.jessechanrui.template.req18.pdf.itext.pdf;

import cn.com.agree.afa.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import ibs.server.jjp.scene.consts.JjpTradeConsts;

import java.awt.*;
import java.math.BigDecimal;

/**
 * @author liaow
 */
public class PdfUtils {
	public static final String PAGE = "page";
	public static final String PARAGRAPH = "paragraph";
	public static final String TABLE = "table";
	public static final String PAGENUMBER = "pagenumber";
	public static final String SIGNATURE = "signature";
	
	public static final String STARTCHAR = "[";
	public static final String ENDCHAR = "]";
	public static final String COMMA = ", ";
	
	public static final String FONT1 = "simhei";
	public static final String FONT2 = "等线";
	public static final String FONT3 = "simfang";
	
	public static final String STSONGLIGHT = "STSong-Light";
	
	/**
	 * 毫米转 pt
	 */
	public static float mm2pt(float mm) {
		// 毫米转 pt
		return mm * 72f / 25.4f;
	}
	
	
	/**
	 * 获取Float值
	 */
	public static float objectToFloat(JSONObject paraObj, String key, float defaultValue) {
		float result = defaultValue;
		Object leadingObject = (Object) paraObj.getOrDefault(key, null);
		if (leadingObject != null) {
			result = ((BigDecimal) leadingObject).floatValue();
		}
		return result;
	}
	
	
	/**
	 * 生成颜色对象
	 */
	public static Color str2color(String value) {
		String[] color = value.split(", ");
		return new Color(Integer.parseInt(color[0]), Integer.parseInt(color[1]), Integer.parseInt(color[2]));
	}

	
	/**
	 * 格式化返回值
	 */
	public static String formatValue(String key, String value) {
		String formatValue = "";
		switch (key) {
		case JjpTradeConsts.STATUS:
			switch (value) {
			case JjpTradeConsts.BATCH_STATUS_0:
				formatValue = "初始化";
				break;
			case JjpTradeConsts.BATCH_STATUS_3:
				formatValue = "失败";
				break;
			case JjpTradeConsts.BATCH_STATUS_W:
				formatValue = "成功";
				break;
			case JjpTradeConsts.BATCH_STATUS_Z:
				formatValue = "批次异常(人工处理)";
				break;
			default:
				formatValue = "处理中";
				break;
			}
			break;
		case JjpTradeConsts.HOSTSTATUS:
			switch (value) {
			case JjpTradeConsts.BATCHDETAIL_HOSTSTATUS_0:
				formatValue = "失败";
				break;
			case JjpTradeConsts.BATCHDETAIL_HOSTSTATUS_1:
				formatValue = "成功";
				break;
			case JjpTradeConsts.BATCHDETAIL_HOSTSTATUS_2:
				formatValue = "已退汇";
				break;
			case JjpTradeConsts.BATCHDETAIL_HOSTSTATUS_9:
				formatValue = "待处理";
				break;
			default:
				formatValue = value;
				break;
			}
			break;
		case JjpTradeConsts.ERRORMSG:
			if(StringUtils.isNullOrEmpty(value) || JjpTradeConsts.ERRORCODE_SUCCESS.equals(value)) {
				formatValue = "";
				break;
			}
			if(value.length()>JjpTradeConsts.MSG_LENGTH) {				
				formatValue = value.substring(0, JjpTradeConsts.MSG_LENGTH);
			}else {
				formatValue = value;
			}
		default:
			break;
		}
		return formatValue;
	}
}
